<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Region extends Model
{
    //
    protected $table = 'region';

    /**
     * 获取详细地址
     * @method getAddress
     * @author chengzhigang<1256699215@qq.com>
     * @param $province 省 $city 市 $district 县  $address 详细地址
     * @return string
     */
    public static function getAddress($provinceId,$cityId,$districtId,$address){
        $newAddress = "";
        if($provinceId){
            $province = self::where('id',$provinceId)->value('name');
            if(empty($province)){
                return ['status'=>2,'msg'=>'省级地址查不到'];
            }else{
                $newAddress .= $province;
            }
        }
        if($cityId){
            $city = self::where('id',$cityId)->value('name');
            if(empty($city)){
                return ['status'=>2,'msg'=>'市级地址查不到'];
            }else{
                $newAddress .=  ' ' . $city;
            }
        }
        if($districtId){
            $district = self::where('id',$districtId)->value('name');
            if(empty($district)){
                return ['status'=>2,'msg'=>'市级地址查不到'];
            }else{
                $newAddress .=  ' ' . $district;
            }
        }
        $newAddress .= ' ' . $address;
        return ['status'=>1,'msg'=>'查询成功','data'=>$newAddress];
    }

}
